#include<bits/stdc++.h>
using namespace std;

int r, c;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
bool vis[100][100];
char ch[100][100];

struct node{
	int x, y, beginCost, endCost, step;
	bool operator < (const node &b) const {
		return beginCost+endCost > b.beginCost+b.endCost;
	}
};

int qx = 0, qy = 0;
int zx, zy;	// assign in main

void bfs(){
	priority_queue<node> q;
	q.push({qx, qy, 0, zx-qx+zy-qy, 1});
	vis[qx][qy] = 1;
	
	while(!q.empty()){
		node t = q.top();
		q.pop();
		
		if(t.x == zx && t.y == zy){
			cout<<t.step;
			return ;
		}
		
		for(int i = 0;i < 4;i++){
			int xx = t.x+dx[i];
			int yy = t.y+dy[i];
			int bb = t.x+t.y;
			int ee = (zx-xx)+(zy-yy);
			int ss = t.step+1;
			if(xx < r && yy < c && xx >= 0 && yy >= 0 && !vis[xx][yy] && ch[xx][yy] == '.'){
				q.push({xx, yy, bb, ee, ss});
				vis[xx][yy] = 1;
			}
		}
	}
}

int main(){
	cin>>r>>c;
	zx = r-1, zy = c-1;
	for(int i = 0;i < r;i++){
		for(int j = 0;j < c;j++){
			cin>>ch[i][j];
		}
	}
	bfs();
	return 0;
}
